define(["jquery","bbcare","fu/app/datatable/datatable.servers",
    "fu/app/datatable/datatable.ui"],function($,$bb,$datatableServers,$datatableUi){
	var servers = {};
	var URL = $bb.baseUrl("followup");

	/**
	 * 请求项目接口
	 */
	servers.ajaxProject = function(callback){
		$bb.ajax({
			url: URL + "followup/service/exportExcel/gettenantIdforProject",
			success: function(data){
				if(data.success){ 
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求项目接口出错！");
				}
			}
		});
	}

	/**
	 * 请求导出接口
	 */
	servers.ajaxExport = function(params,callback){
		$bb.ajax({
			url: URL + "followup/service/exportExcel/updaload",
			data:JSON.stringify({
				data : params
			}),
			success: function(data){
				callback(data,params);
			}
		});
	}

	/**
	 * 下载
	 */
	servers.ajaxUpload = function(params,callback){
		$bb.ajax({
			url: URL + "followup/service/exportExcel/getURLToUpload",
			data:JSON.stringify({
				data : params
			}),
			success: function(data){
				if(data.success){ 
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求下载接口出错！");
				}
			}
		});
	}

	/**
     * 入参
     */
    var inParams = function(args){
        var data = JSON.stringify({
            data: {
                "args": JSON.stringify(args),
                "projectId": $.trim($("#exportListProject").val()),
                "beginTime": $.trim($("#exportListStartTime").val()),
                "endTime": $.trim($("#exportListEndTime").val()),
            }
        });
        return data;
    }
    /**
     * 出参
     */
    var outParams = function(data){
        return data.rows;
    }
    /**
     * columns
     */
    var columnsDown = function(e){
        var h = '<a href="' + e.fileurl + '">下载</a>';
        return h;
    }
    var columnsData = function(){
        var columnsArr = [
            {"data":"createTime"},
            {"data":"project_name"},
            {"data":"mouth"},
            {"data":"doctor_name"},
            {"data":columnsDown}
        ];
        return columnsArr;
    }
    /**
     * 初始化完成之后的回调函数
     */
    var initComplete = function(setting,json){
        $("#exportList").prev("div.row").remove();
        $(".data-export-select").unbind("click");
		$(".data-export-select").click(function(){
            $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatableUi.table.api().ajax.params();   //获取dt请求参数
		});
    }
    /**
     * 获取datatable里的options
     */
    servers.getOptions = function(){
        var sessionId = $bb.getSessionStorage("sessionId");
        var options = {
            "ajax": {
                "url": URL + "followup/service/exportExcel/getURLToUploadDate?sessionId=" + sessionId,
                "data": inParams,
                "dataSrc": outParams
            },
            "columns": columnsData(),
            "initComplete": initComplete,
        };
        return options;
    }

	return servers;
});